home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 20 / Cream of the Crop 20 (Terry Blount) (1996).iso / utility / freedos.zip / COM050.ZIP / LH.ASM < prev    next >
Assembly Source File  |  1996-01-17  |  4KB  |  182 lines

  1.         TITLE   LH.ASM
  2.  
  3. ; This file contains DOS interface functions used by LOADHIGH.C
  4.  
  5. DGROUP  GROUP   _DATA
  6.         ASSUME  CS:_TEXT, DS:DGROUP
  7.  
  8. _DATA   SEGMENT WORD PUBLIC 'DATA'
  9.         extrn   _UMBLink:WORD           ; Holds the current state of the UMB link
  10. _DATA   ENDS
  11.  
  12. _TEXT   SEGMENT WORD PUBLIC 'CODE'
  13.  
  14.         public  _DosSetUMBLink, _DosSetStrategy
  15.         public  _DosAlloc, _DosResize, _DosFree
  16.         public  _farmemcmp, _GetFirstMCB
  17.         
  18. frame   equ     [bp+4]          ; points to the stack frame
  19.  
  20. ; Most of these functions are just an interface between a C program and 
  21. ; the int 21h API. They load the registers from their parameters, and makes 
  22. ; an int 21h call.
  23.  
  24. _DosAlloc       PROC NEAR   ; Allocate a DOS memory block
  25.         push    bp
  26.         mov     bp, sp
  27.   
  28.         mov     ah, 48h
  29.         mov     bx, frame
  30.         call    calldos
  31.         jnc     alloc_ok
  32.         xor     ax, ax
  33.  
  34. alloc_ok:
  35.         pop     bp
  36.         ret
  37. _DosAlloc ENDP
  38.  
  39. ; DosSetUMBLink:
  40. ;
  41. ; Set the UMB link. The global variable UMBLink will reflect
  42. ; the new state of the UMB link. The return value is the old 
  43. ; state of the UMB link.
  44.  
  45. _DosSetUMBLink PROC NEAR
  46.         push    bp
  47.         mov     bp, sp
  48.         push    si
  49.  
  50.         mov     ax, 5802h       ; get UMB link
  51.         call    calldos
  52.         mov     si, ax          ; save the old state
  53.         and     si, 0ffh
  54.  
  55.         mov     ax, 5803h       ; set UMB link
  56.         mov     bx, word ptr frame
  57.         call    calldos
  58.         mov     ax, frame
  59.         jnc     yup
  60.         xor     ax, ax
  61.  
  62. yup:    mov     DGROUP:_umbLink, ax
  63.         mov     ax, si
  64.  
  65.         pop     si
  66.         pop     bp
  67.         ret
  68. _DosSetUMBLink ENDP
  69.  
  70. _DosSetStrategy PROC NEAR
  71. ; set the new malloc strategy,  and return the old
  72.         
  73.         push    bp
  74.         mov     bp, sp
  75.         push    si
  76.    
  77.         mov     ax, 5800h
  78.         call    calldos
  79.         mov     si, ax          ; save the old strategy
  80.         
  81.         mov     ax, 5801h
  82.         mov     bx, word ptr frame      ; new strategy
  83.         call    calldos
  84.  
  85.         mov     ax, si
  86.         pop     si
  87.         pop     bp
  88.         ret
  89. _DosSetStrategy ENDP
  90.  
  91. _DosFree PROC NEAR
  92. ; free a memory block
  93.         push    bp
  94.         mov     bp, sp
  95.  
  96.         mov     es, word ptr frame    ; memory block to free
  97.         mov     ah, 49h
  98.         call    calldos
  99.  
  100.         pop     bp
  101.         ret
  102. _DosFree ENDP
  103.  
  104. _DosResize PROC NEAR
  105. ; resize a memory block
  106.  
  107.         push    bp
  108.         mov     bp, sp
  109.  
  110.         mov     es, word ptr frame     ; memory block to resize
  111.         mov     bx, word ptr frame+2   ; new size
  112.         mov     ah, 4ah
  113.         call    calldos
  114.         jc      resize_err
  115.         xor     ax, ax
  116.  
  117. resize_err:
  118.         pop     bp
  119.         ret
  120. _DosResize ENDP
  121.  
  122. _GetFirstMCB PROC
  123. ; Get start of MCB chain, from word ptr SYSVARS[-2]
  124.  
  125.         mov     ah, 52h
  126.         call    calldos
  127.         mov     ax, word ptr es:[bx-2]
  128.         ret
  129. _GetFirstMCB ENDP
  130.  
  131. _farmemcmp PROC NEAR
  132.  
  133. ; Does a simple compare between two far memory pointers.
  134. ; Returns zero if they're equal, non-zero if not.
  135.  
  136.         push    bp
  137.         mov     bp, sp
  138.         push    ds
  139.         push    si
  140.         push    di
  141.  
  142.         lds     si, frame
  143.         les     di, frame+4
  144.         mov     cx, frame+8
  145.         xor     ax, ax
  146.         repe    cmpsb
  147.         je      get_out
  148.         
  149.         dec     ax
  150.  
  151. get_out:        
  152.         pop     di
  153.         pop     si
  154.         pop     ds
  155.         pop     bp
  156.         ret
  157. _farmemcmp ENDP
  158.  
  159. calldos PROC NEAR
  160.  
  161. ; This routine is used to call DOS.
  162. ; Some DOS versions don't always save registers as they should.
  163. ; By using this function, this won't be a problem.
  164.  
  165.         push    si
  166.         push    di
  167.         push    bp
  168.  
  169.         clc
  170.         int     21h
  171.  
  172.         pop     bp
  173.         pop     di
  174.         pop     si
  175.         ret
  176. calldos ENDP
  177.  
  178. _TEXT   ENDS
  179.         END
  180.  
  181.  
  182.